//
//  LGSearchBar.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/4/14.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import UIKit

var LGSearchBarHeight = 30 as CGFloat

class LGSearchBar: UIView {

    var textField:LGTextField?
    var cancelButton:UIButton?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.configure()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    fileprivate func configure() {
        self.textField = LGTextField.init()
        self.textField?.returnKeyType = UIReturnKeyType.search
        self.textField?.leftViewMode = UITextFieldViewMode.always
        self.textField?.placeholder = "歌曲 歌手 专辑"
        self.textField?.clipsToBounds = true
        self.textField?.layer.cornerRadius = LGSearchBarHeight/2
        self.textField?.font = SM_CFont(18)
        self.textField?.tintColor = UIColor.init(red: 0, green: 0.77, blue: 1, alpha: 1)
        self.textField?.backgroundColor = UIColor.white.withAlphaComponent(0.7)
        let leftButton = UIButton.init()
        leftButton.setImage(UIImage.init(named: "icon_search_small"), for: UIControlState.normal)
        leftButton.sizeToFit()
        self.textField?.leftView = leftButton
        self.addSubview(self.textField!)
        self.textField?.snp.makeConstraints({ (make) in
            make.left.equalTo(SM_SIZE(20))
            make.top.bottom.equalTo(0)
        })

        self.cancelButton = UIButton.init()
        self.cancelButton?.setTitle(NSLocalizedString("cancel_title", comment: "default"), for: UIControlState.normal)
        self.addSubview(self.cancelButton!)
        self.cancelButton?.layer.cornerRadius = LGSearchBarHeight/2
        self.cancelButton?.setTitleColor(UIColor.lightGray, for: UIControlState.normal)
        self.cancelButton?.clipsToBounds = true
        self.cancelButton?.titleLabel?.font = SM_CFont(20)
        self.cancelButton?.backgroundColor = UIColor.white.withAlphaComponent(0.7)
        self.cancelButton?.snp.makeConstraints({ (make) in
            make.left.equalTo((self.textField?.snp.right)!).offset(SM_SIZE(20))
            make.right.equalTo(SM_SIZE(-20))
            make.top.bottom.equalTo(0)
            make.width.equalTo(SM_SIZE(140))
        })
    }


}
